#include"DirectXFramework.h"

void CDirectXFramework::Render(float deltaTime)
{
	//Test if the Device was Created Successfully//
	if(!m_pD3DDevice)
		//return if Device was not Created Successfully//
		return;

	//Clear Back Buffer//
	if(SUCCEEDED(m_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DXCOLOR(0.0f, 0.4f, 0.8f, 1.0f), 1.0f, 0)))
	{
		if(SUCCEEDED(m_pD3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0)))
		{
			//Begin the Scene//
			if(SUCCEEDED(m_pD3DDevice->BeginScene()))
			{
				//Camera//
				D3DXMatrixLookAtLH(&m_matView,
					& (m_Camera.getCameraPosition()), // the camera position
					& (m_Camera.getCameraLookAt()), // the look-at position
					& (D3DXVECTOR3 (0.0f, 1.0f, 0.0f))); // the up direction
				m_pD3DDevice->SetTransform(D3DTS_VIEW, &m_matView);

				D3DXMatrixPerspectiveFovLH(&m_matProj,
					D3DXToRadian(45),    // the horizontal field of view
					(float)SCREEN_WIDTH / (float)SCREEN_HEIGHT,    // aspect ratio
					1.0f,    // the near view-plane
					1000.0f);    // the far view-plane
				m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &m_matProj);    // set the projection transform

				switch(m_GameState)
				{
				case MENU:
					{
						//Menu Buttons//
						for(int button = 0; button < NumberOfButtons; button++)
						{

							//Reset Matrices//
							D3DXMatrixIdentity(&m_matTrans);
							D3DXMatrixIdentity(&m_matScale);
							D3DXMatrixIdentity(&m_matRot);
							D3DXMatrixIdentity(&m_matWorld);

							//Buttons//
							//Set the texture//
							m_pD3DDevice->SetTexture(0, m_Menu.getTexture(button));
							//scale
							D3DXMatrixScaling(&m_matScale,.25f,.25f,.25f);
							//multiply
							D3DXMatrixMultiply(&m_matWorld,&m_matWorld,&m_matScale);
							//Translate//
							D3DXMatrixTranslation(&m_matTrans, m_Menu.getButton(button).getX(), m_Menu.getButton(button).getY(), -10.0f);
							//multiply//
							D3DXMatrixMultiply(&m_matWorld,&m_matWorld,&m_matTrans);
							m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matWorld));
							//Draw the Buttons//
							m_Menu.getMesh()->DrawSubset(0);

							//If the Pick State is set to Pick//
							if(m_PickThis == BUTTONS && m_PickState == PICK)
							{
								//set the distance to a negative value (to make sure we don't accidently think we picked something//
								m_PickObject = -1;
								//Call pick and pass in a number of what we are picking//
								//In this case it's a button number, in others it may be a pawn number or card number//
								m_PickObject = Pick(button);
							}


							//Draw the Text overlay for the Buttons//
							//I used define statements to set up the colors
							//then checked the state of the button to see what color to use
							if(m_Menu.getButton(button).getState() == 0)
							{
								m_menuFontColor = WHITE;
							}
							else
							{
								m_menuFontColor = BLACK;
							}
							//draw the menu font with correct color
							m_pD3DFont->DrawText(0, m_Menu.getButton(button).getText(), -1, m_Menu.getButton(button).getRECT(), DT_CENTER | DT_VCENTER | DT_NOCLIP, m_menuFontColor);

							//do all kinds of stuff and pass in the texture number
							renderBackground(T_MENU);


						}
					}
					break;
				case RULES:
					{
						renderBackground(T_RULES);
					}
					break;
				case CONTROL:
					{
						renderBackground(T_CONTROL);
					}
					break;
				case CREDITS:
					{
						renderBackground(T_CREDITS);
					}
					break;
				case PLAY:
					{
						///Gary code////
						//drawing the roboPawns
						//Reset Matrices//
						D3DXMatrixIdentity(&m_matTrans);
						D3DXMatrixIdentity(&m_matScale);
						D3DXMatrixIdentity(&m_matRot);
						D3DXMatrixIdentity(&m_matWorld);
						D3DXMatrixIdentity(&m_matRotateY);

						//loop through all our players
						for(int player = 0; player < NumberOfPlayers; player++)
						{
							//loop through all of players pawns
							for(int pawn = 0; pawn < NumberOfPawns; pawn++)
							{

								//sets the texture
								m_pD3DDevice->SetTexture(0, m_PlayerController.getTexture(player));

								//go through the motions using temp to take the info into transformations
								//scal could be included in the function getPawns
								D3DXMatrixScaling(&m_matScale, .1f,.1f,.1f);
								D3DXMatrixRotationY(&m_matRotateY, m_Players[player].getPawns(pawn).getRotateY());		
								D3DXMatrixTranslation(&m_matTrans, m_Players[player].getPawns(pawn).getPosX(), m_Players[player].getPawns(pawn).getPosY(), m_Players[player].getPawns(pawn).getPosZ());
								D3DXMatrixMultiply(&m_matScale, &m_matScale, &m_matRotateY);		
								D3DXMatrixMultiply(&m_matWorld, &m_matScale, &m_matTrans);	
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matWorld));

								if(m_PickThis == PAWNS && m_PickState == PICK)
								{
									//This is used to get the right mesh for the pick//
									m_PlayerToBePicked = player;
									//set the distance to a negative value (to make sure we don't accidently think we picked something//
									m_PickObject = -1;
									//Call pick and pass in a number of what we are picking//
									//In this case it's a button number, in others it may be a pawn number or card number//
									m_PickObject = Pick(pawn);
									//This will keep the value of the player picked//
									if(m_PickObject != -1)
									{
										m_PlayerPicked = player;
										m_PawnPicked = pawn;
										m_PickThis = NONE;
										m_PickState = WAIT;
									}
								}

								//draw our robot mesh
								m_PlayerController.getMesh(player)->DrawSubset(0);
							}
						}
						//end of roboPawns

						//------------------------------------------------//
						//Hand Cards//
						if (m_Hand[m_PlayerTurn].GetVisible() && m_MapState == HIDDEN)
						{
							for (int i=0; i < 5; i++)
							{
								//Reset Matrices//
								D3DXMatrixIdentity(&m_matTrans);
								D3DXMatrixIdentity(&m_matScale);
								D3DXMatrixIdentity(&m_matRot);
								D3DXMatrixIdentity(&m_matWorld);

								m_pD3DDevice->SetTexture(0, m_Deck.GetTexture(m_Hand[m_PlayerTurn].GetCard(i).value));

								//Rotate//
								D3DXMatrixRotationX(&m_matRot, D3DXToRadian(-75));

								//Translate//
								D3DXMatrixTranslation(&m_matTrans,
									m_Camera.getCameraPosition().x - 8 + (i * 4),
									m_Camera.getCameraPosition().y - 20,
									m_Camera.getCameraPosition().z - 0.5f);

								//Multiply rotate and translation, store in world//
								D3DXMatrixMultiply(&m_matWorld, &m_matRot, &m_matTrans);

								//Set Transform//
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matWorld));

								if(m_PickThis == CARDS && m_PickState == PICK)
								{
									m_PickObject = -1;
									m_PickObject = Pick(i);

									if(m_PickObject >= 0)
									{
										m_CardPicked = i;
									}
								}

								//Draw the Card
								m_Deck.GetMesh()->DrawSubset(0);

								if(m_PickThis == CARDS && m_PickState == PICK)
								{
									//set the distance to a negative value (to make sure we don't accidently think we picked something//
									m_PickObject = -1;
									//Call pick and pass in a number of what we are picking//
									//In this case it's a button number, in others it may be a pawn number or card number//
									m_PickObject = Pick(i);
									if(m_PickObject >= 0)
									{
										m_CardPicked = i;
									}
								}
							}
						}

						//Board Tiles//
						for(int TileIndex= 0; TileIndex < NumberOfTiles; TileIndex++)
						{
							//Reset Matrices//
							D3DXMatrixIdentity(&m_matTrans);
							D3DXMatrixIdentity(&m_matScale);
							D3DXMatrixIdentity(&m_matRot);
							D3DXMatrixIdentity(&m_matWorld);
							m_pD3DDevice->SetTexture(0, tileFrameTex);

							//Set the texture for the specific type of tile//
							switch(m_Board.GetBoardTile(TileIndex).getSlideType())
							{
							case START0:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(START0));	break;
							case SLIDE0:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(SLIDE0));	break;
							case FINISH0:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(FINISH0));	break;
							case START1:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(START1));	break;
							case SLIDE1:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(SLIDE1));	break;
							case FINISH1:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(FINISH1));	break;
							case START2:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(START2));	break;
							case SLIDE2:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(SLIDE2));	break;
							case FINISH2:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(FINISH2));	break;
							case START3:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(START3));	break;
							case SLIDE3:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(SLIDE3));	break;
							case FINISH3:
								m_pD3DDevice->SetTexture(0, m_Board.getSlideTexture(FINISH3));	break;
							case NORMAL:
								m_pD3DDevice->SetTexture(0, m_Board.getGreen());	break;
							default:
								m_pD3DDevice->SetTexture(0, m_Board.getGreen());
							}

							//Translate//
							D3DXMatrixTranslation(&m_matTrans, m_Board.GetBoardTile(TileIndex).getX(), -10.0f, m_Board.GetBoardTile(TileIndex).getZ());
							//Set Transform//
							m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matTrans));

							//Draw the Tile//
							m_Board.getMesh()->DrawSubset(0);

							//If the Pick State is set to Pick//
							if(m_PickThis == TILES && m_PickState == PICK)
							{
								//set the distance to a negative value (to make sure we don't accidently think we picked something//
								m_PickObject = -1;
								m_HomeStretchPicked = -1; //Set these to -1 to make sure the proper tile function is carried out in update//
								m_HomePicked = -1;
								//Call pick and pass in a number of what we are picking//
								//In this case it's a button number, in others it may be a pawn number or card number//
								m_PickObject = Pick(TileIndex);
								if(m_PickObject >= 0)
								{
									m_TilePicked = TileIndex;
								}
							}

							if(m_Board.GetBoardTile(TileIndex).getHightlight() == true)
							{
								RunShader(m_Board.GetBoardTile(TileIndex).getX(), m_Board.GetBoardTile(TileIndex).getZ());
							}
						}

							//Home Stretches//
							for(int PlayerIndex = 0; PlayerIndex < NumberOfPlayers; PlayerIndex++)
							{
								for(int HomeIndex= 0; HomeIndex < NumberOfStretch; HomeIndex++)
								{
									//Reset Matrices//
									D3DXMatrixIdentity(&m_matTrans);
									D3DXMatrixIdentity(&m_matScale);
									D3DXMatrixIdentity(&m_matRot);
									D3DXMatrixIdentity(&m_matWorld);

									//Set the texture//
									m_pD3DDevice->SetTexture(0, m_Board.getHomeStretchTexture(PlayerIndex));
									//Translate//
									D3DXMatrixTranslation(&m_matTrans, m_Board.GetPlayerHomeStretch(PlayerIndex, HomeIndex).getX(), -10.0f, m_Board.GetPlayerHomeStretch(PlayerIndex, HomeIndex).getZ());
									//Set Transform//
									m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matTrans));
									//Draw the Tile//
									m_Board.getMesh()->DrawSubset(0);
									//If the Pick State is set to Pick//
									if(m_PickThis == TILES && m_PickState == PICK)
									{
										//set the distance to a negative value (to make sure we don't accidently think we picked something//
										m_PickObject = -1;
										//Call pick and pass in a number of what we are picking//
										//In this case it's a button number, in others it may be a pawn number or card number//
										m_PickObject = Pick(HomeIndex);
										if(m_PickObject >= 0)
										{
											m_TilePicked = HomeIndex;
											m_HomeStretchPicked = PlayerIndex;
										}
									}
									if(m_Board.GetPlayerHomeStretch(PlayerIndex, HomeIndex).getHightlight() == true)
									{
										RunShader(m_Board.GetPlayerHomeStretch(PlayerIndex, HomeIndex).getX(), m_Board.GetPlayerHomeStretch(PlayerIndex, HomeIndex).getZ());
									}
								}

								//Player Starts//

								//Reset Matrices//
								D3DXMatrixIdentity(&m_matTrans);
								D3DXMatrixIdentity(&m_matScale);
								D3DXMatrixIdentity(&m_matRot);
								D3DXMatrixIdentity(&m_matWorld);
								//Set the texture//
								m_pD3DDevice->SetTexture(0, m_Board.getStartTexture(PlayerIndex));
								D3DXMatrixScaling(&m_matScale,1.5,1.0f,1.5);

								//Translate//
								D3DXMatrixTranslation(&m_matTrans, m_Board.GetPlayerStart(PlayerIndex).getX(), -10.0f, m_Board.GetPlayerStart(PlayerIndex).getZ());

								D3DXMatrixMultiply(&m_matScale, &m_matScale, &m_matTrans);
								//Set Transform//
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matScale));
								//Draw the Tile//
								m_Board.getMesh()->DrawSubset(0);
								//If the Pick State is set to Pick//
								if(m_PickThis == TILES && m_PickState == PICK)
								{
									//set the distance to a negative value (to make sure we don't accidently think we picked something//
									m_PickObject = -1;
									//Call pick and pass in a number of what we are picking//
									//In this case it's a button number, in others it may be a pawn number or card number//
									m_PickObject = Pick(PlayerIndex);
								}

								//Player Homes//

								//Reset Matrices//
								D3DXMatrixIdentity(&m_matTrans);
								D3DXMatrixIdentity(&m_matScale);
								D3DXMatrixIdentity(&m_matRot);
								D3DXMatrixIdentity(&m_matWorld);
								//Set the texture//
								m_pD3DDevice->SetTexture(0, m_Board.getHomeTexture(PlayerIndex));

								D3DXMatrixScaling(&m_matScale,1.5f,1.0f,1.5f);
								//Translate//
								D3DXMatrixTranslation(&m_matTrans, m_Board.GetPlayerHome(PlayerIndex).getX(), -10.0f, m_Board.GetPlayerHome(PlayerIndex).getZ());
								D3DXMatrixMultiply(&m_matScale, &m_matScale, &m_matTrans);
								//Set Transform//
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matScale));
								//Draw the Tile//
								m_Board.getMesh()->DrawSubset(0);
								//If the Pick State is set to Pick//
								if(m_PickThis == TILES && m_PickState == PICK)
								{
									m_PickObject = Pick(PlayerIndex);
									if(m_PickObject != -1)
									{
										m_HomePicked = m_PickObject;
									}
								}
								if(m_Board.GetPlayerHome(PlayerIndex).getHightlight() == true)
								{
									RunShader(m_Board.GetPlayerHome(PlayerIndex).getX(), m_Board.GetPlayerHome(PlayerIndex).getZ());
								}
							}

							//this section draws the posters
							//which are the numbers on the start, home tiles
							//this also draws the circuit board
							//prbably can be compacted some more down the road

							//make sthe format and stream for the  poster mesh verts
							m_pD3DDevice->SetFVF(CUSTOMFVF_1);
							m_pD3DDevice->SetStreamSource(0, m_buffer, 0, sizeof(CUSTOMVERTEX));

							//transition matrixs for posters
							D3DXMATRIX rotateX;
							D3DXMATRIX rotateY;
							D3DXMATRIX translate;
							D3DXMATRIX scale;


							//this one is for start num posters
							for(int num = 0; num < NumberOfPlayers;num++)
							{
								D3DXVECTOR3 temp = m_startBoards[num].getPos();

								m_pD3DDevice->SetTexture(0, m_numberMeshTex[m_Players[num].getNumAtStart()]);//numberMeshTex[numBoards[num].getNumber()]
								D3DXMatrixScaling(&scale,1.5f,1.5f,1.5f);
								D3DXMatrixRotationY(&rotateY,3.15f);
								D3DXMatrixMultiply(&rotateY, &rotateY, &scale);
								D3DXMatrixRotationX(&rotateX, 1.5);
								D3DXMatrixMultiply(&rotateX, &rotateX, &rotateY);
								D3DXMatrixTranslation(&translate,temp.x,-4.5f,temp.z);//y = -4.5
								D3DXMatrixMultiply(&rotateX, &rotateX, &translate);
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(rotateX));
								m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

							}

							//this is for home number posters
							for(int num = 0; num < NumberOfPlayers;num++)
							{
								D3DXVECTOR3 temp = m_homeBoards[num].getPos();

								m_pD3DDevice->SetTexture(0, m_numberMeshTex[m_Players[num].getNumAtHome()]);//numberMeshTex[numBoards[num].getNumber()]
								D3DXMatrixScaling(&scale,1.5f,1.5f,1.5f);
								D3DXMatrixRotationY(&rotateY,3.15f);
								D3DXMatrixMultiply(&rotateY, &rotateY, &scale);
								D3DXMatrixRotationX(&rotateX, 1.5);
								D3DXMatrixMultiply(&rotateX, &rotateX, &rotateY);
								D3DXMatrixTranslation(&translate,temp.x,-4.5f,temp.z);//y = -4.5
								D3DXMatrixMultiply(&rotateX, &rotateX, &translate);
								m_pD3DDevice->SetTransform(D3DTS_WORLD, &(rotateX));
								m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

							}

							//this is for circuit board poster
							D3DXVECTOR3 temp = m_cirBoard.getPos();

							m_pD3DDevice->SetTexture(0, m_cirBoardTex);
							D3DXMatrixScaling(&scale,50.0f,0,40.0f);
							D3DXMatrixRotationY(&rotateY,3.15f);
							D3DXMatrixMultiply(&rotateY, &rotateY, &scale);
							D3DXMatrixRotationX(&rotateX, 1.75);
							D3DXMatrixMultiply(&rotateX, &rotateX, &rotateY);
							D3DXMatrixTranslation(&translate,temp.x,temp.y,temp.z);
							D3DXMatrixMultiply(&rotateX, &rotateX, &translate);
							m_pD3DDevice->SetTransform(D3DTS_WORLD, &(rotateX));
							m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

						}

					break;
				}

				//Begin Sprite//
				if(SUCCEEDED(m_pD3DSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_FRONTTOBACK)))
				{

				}

				//Close the Sprite//
				m_pD3DSprite->End();

				//Text//

				//Find Window Size//
				RECT rect;
				GetWindowRect(m_hWnd, &rect);
				rect.right = rect.right - rect.left;
				rect.bottom = rect.bottom - rect.top;
				rect.left = 0;
				rect.top = 0;

				RECT rect1 = rect;			
				rect1.right = rect1.right - rect1.left;
				rect1.bottom = rect1.bottom - rect1.top;
				rect1.left = 0;
				rect1.top = SCREEN_HEIGHT - 60;

				//for setting the title text
				RECT rect2 = rect;
				rect2.right = rect2.right - rect2.left;
				rect2.bottom = rect2.bottom - rect2.top;
				rect2.left = SCREEN_WIDTH/20;
				rect2.top = SCREEN_HEIGHT/3;

				m_pD3DFont->DrawText(0, m_tcDebug, -1, &rect, DT_TOP | DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
				switch(m_GameState)
				{
				case MENU:
					{
						//Draw Text//
						m_pD3DFont->DrawText(0, L"MyBad", -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
						m_pD3DFont->DrawText(0, m_tcMousePosition, -1, &rect, DT_TOP | DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

						//this is the game title text which uses an array of d3dXCOLOR called range to flash colors
						m_pD3DFontBig->DrawText(0,L"MY",-1, &rect2, DT_LEFT | DT_NOCLIP, m_range[m_TitleColorIndex]);
						m_pD3DFontBig->DrawText(0,L"BAD",-1, &rect2, DT_RIGHT | DT_NOCLIP, m_range[m_TitleColorIndex]);
					}

					//this just uses time to change the color
					m_currentTime = timeGetTime() - m_lastTime;
					if(m_currentTime > 675)	
					{
						m_TitleColorIndex++;

						m_lastTime = (float)timeGetTime();
					}
					//cap it
					if(m_TitleColorIndex >= NumberOfButtons)
					{
						m_TitleColorIndex = 0;
					}

					m_pD3DFont->DrawText(0,L"W-S (keyboard) TO CHOOSE, LEFT ANALOG or MOUSE\nHIT ENTER (keyboard) OR A (contoller) TO CONTINUE",-1, &rect1, DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					break;

				case RULES:
					{

						m_pD3DFont->DrawText(0, L"RULES", -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
						m_pD3DFont->DrawText(0,L"HIT C (keyboard) OR A (contoller) TO CONTINUE TO CONTROLS \nHIT B (keyboard) OR BACK (contoller) TO RETURN ",-1, &rect1, DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

						//m_pD3DFont->DrawText(0, m_tcMousePosition, -1, &rect, DT_TOP | DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					}
					break;
				case CONTROL:
					{

					m_pD3DFont->DrawText(0, L"CONTROL", -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					m_pD3DFont->DrawText(0,L"HIT B (keyboard) OR BACK (contoller) TO RETURN ",-1, &rect1, DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
						//m_pD3DFont->DrawText(0, m_tcMousePosition, -1, &rect, DT_TOP | DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					}
					break;
				case CREDITS:
					{

						m_pD3DFont->DrawText(0, L"CREDITS", -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
						m_pD3DFont->DrawText(0,L"HIT B(keyboard) OR BACK (contoller) TO RETURN",-1, &rect1, DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
						//m_pD3DFont->DrawText(0, m_tcMousePosition, -1, &rect, DT_TOP | DT_CENTER | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					}
					break;
				case PLAY:
					{
						wsprintf(m_tcKB, L"Player %u's Turn", m_PlayerTurn+1);
						m_pD3DFont->DrawText(0, m_tcKB, -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
					}
					break;
				}

				//Calculate Frames Per Second//
				CalculateFPS();
				//Draw Frames Per Second to the Screen//
				m_pD3DFont->DrawText(0, m_tcFPS, -1, &rect, DT_TOP | DT_LEFT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

				//EndScene//
				m_pD3DDevice->EndScene();
			}
			m_pD3DDevice->Present(0,0,0,0);
		}
	}
	//Set Pick to WAIT, we will not pick outside the Render() function//
	m_PickState = WAIT;
}


void CDirectXFramework::RunShader(float TileX, float TileZ)
{
	//Reset Matrices//
	D3DXMatrixIdentity(&m_matTrans);
	D3DXMatrixIdentity(&m_matScale);
	D3DXMatrixIdentity(&m_matRot);
	D3DXMatrixIdentity(&m_matWorld);

	//-------------------------------------------------------------------
	//setting up for the highlight mesh sheader
	//use getTime to set up a timer for changing the color index
	//in the shader
	m_currentTime = timeGetTime() - m_lastTime;
	//I messed with a lot of values but 75 works good
	//when 75 rolls around increase the shader index which
	//gets passed on to the shader
	if(m_currentTime > 75)
	{
		m_shaderIndex += 1;
		//grab the time
		m_lastTime = (float)timeGetTime();
	}
	//capping the index
	if(m_shaderIndex > 3)
	{							
		m_shaderIndex = 1;
	}
	//this is used to increase the value of the color
	//in our shader by specific use in a float4
	m_shaderPercent += .01f;
	//this caps the value between 20-90%
	//theoreticlly
	if(m_shaderPercent > .90)
	{							
		m_shaderPercent = (float).2;
	}

	//so I set a number to the first highlite in the array
	//in Init.cpp to tell us how many we need to draw
	//so know we grab that value and draw how many we need
	for(int frame = 0; frame < highLite[0].getNumber(); frame++)
	{
		//i use this temp vector3 to get the info i need
		//which I pass on when drawing
		D3DXVECTOR3 temp = highLite[frame].getPos();

		m_pD3DDevice->SetTexture(0, tileFrameTex);

		//go through the motions using temp to take the info into transformations
		//scal could be included in the function getPawns
		D3DXMatrixScaling(&m_matScale, .15f,.15f,.15f);
		D3DXMatrixRotationY(&m_matRotateY, 0);		
		D3DXMatrixTranslation(&m_matTrans, TileX, temp.y, TileZ);
		D3DXMatrixMultiply(&m_matScale, &m_matScale, &m_matRotateY);		
		D3DXMatrixMultiply(&m_matWorld, &m_matScale, &m_matTrans);	
		m_pD3DDevice->SetTransform(D3DTS_WORLD, &(m_matWorld));

		//sets up the paramaters we need to grap for the shader fx file
		//these are your standard values sent in for position in world
		m_pEffect->SetTechnique("FirstTechnique");
		m_pEffect->SetMatrix("World", &m_matWorld);
		m_pEffect->SetMatrix("View", &m_matView);
		m_pEffect->SetMatrix("Projection", &m_matProj);
		//these ones I made for our needs to pick the color combo to use
		m_pEffect->SetFloat("numColor",m_shaderPercent);
		m_pEffect->SetFloat("index",m_shaderIndex);

		//the shader pass thingy
		UINT Passes;
		m_pEffect->Begin(&Passes, 0);
		{
			for (UINT Pass = 0; Pass < Passes; ++Pass)
			{
				m_pEffect->BeginPass(Pass);

				/* Render the highlight */
				tileFrame->DrawSubset(0);

				m_pEffect->EndPass();
			}
		}
		m_pEffect->End();
	}
}